// ActionScript file
import flash.events.MouseEvent;

import org.flexlancer.Logger.Logger;

[Bindable]
private var _text:String;

private var _allowRename:Boolean = true;

private function OnCC():void{
	try{
		this.updateHandlers();
	}catch(err:Error){
		Logger.LogE(err);
	}
}

private function OnMouseDown(evt:MouseEvent):void{
	evt.stopImmediatePropagation();
}

public function get allowRename():Boolean{
	return this._allowRename;
}

public function set allowRename(val:Boolean):void{
	this._allowRename = val;
	this.updateHandlers();
}

public function get text():String{
	return this._text;
}

public function set text(val:String):void{
	this._text = val;
}

private function updateHandlers():void{
	try{
		if ( this.lbl == null ) return;
		
		if ( this._allowRename ){
			this.lbl.addEventListener(MouseEvent.DOUBLE_CLICK,Lbl_OnDoubleClick);
			
		}else{
			this.lbl.removeEventListener(MouseEvent.DOUBLE_CLICK,Lbl_OnDoubleClick);
		}
	}catch(err:Error){
		throw err;
	}
}

private function Lbl_OnDoubleClick(evt:MouseEvent):void{
	try{
		this.lbl.visible = false;
		this.txt.visible = true;
	}catch(err:Error){
		Logger.LogE(err);
	}
}

private function Txt_OnEnter():void{
	try{
		this.text = this.txt.text;
		this.txt.visible = false;
		this.lbl.visible = true;
	}catch(err:Error){
		Logger.LogE(err);
	}
}
